package com.bangbang.controller;


import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import com.bangbang.pojo.TbAdvertisingColumn;
import com.bangbang.service.ITbAdvertisingColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 广告栏位分类表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-14
 */
@RestController
@RequestMapping("/groupCourse/tbAdvertisingColumn")
@Api("对广告栏位分类增删改查")
public class TbAdvertisingColumnController {

    @Autowired
    private ITbAdvertisingColumnService columnService;

    @ApiOperation("查询方法")
    @GetMapping
    public Result selectColumn(){
        columnService.query();
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    @ApiOperation("广告栏位新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "col_name",value = "栏位名称",required = true, paramType = "query"),
            @ApiImplicitParam(name = "col_number",value = "可供广告数量",required = true, paramType = "query")
    })
    @PostMapping
    public Result insertColumn(@RequestParam("col_name")String colName, @RequestParam("col_number")Long colNumber){
        columnService.save(new TbAdvertisingColumn().setColName(colName).setColNumber(colNumber));
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    @ApiOperation("广告栏位移除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "col_id",value = "栏位id",required = true, paramType = "path")
    })
    @DeleteMapping("/{col_id}")
    public Result deleteColumn(@PathVariable("col_id")Long colId){
        try {
            columnService.removeById(colId);
            return Result.buildResult(ResultEnum.SUCCESS);
        }catch (Exception e){
            return Result.buildResult(ResultEnum.ERROR).setResult("网络失败，请稍后重试");
        }
    }

}

